<script setup>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
// 数字动态加载
import { useTransition } from '@vueuse/core'
const barContainer = ref(null);
const lineContainer = ref(null);
onMounted(() => {
  // 饼图
  const barchart = echarts.init(barContainer.value);
  const batoption = {
    title: {
      text: '近30天用户地点分布',
      left: 'center'
    },
    responsive: true,
    tooltip: {
      trigger: 'item',
      formatter: '<b>{b}</b> {c}单 <br/>占{d}%'
    },
    toolbox: {
      feature: {
        saveAsImage: { show: true }
      }
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: '近30天统计',
        type: 'pie',
        radius: '70%',
        data: [
          { value: 100, name: '浙江' },
          { value: 73, name: '泉州' },
          { value: 58, name: '南安' },
          { value: 48, name: '福州' },
          { value: 20, name: '晋江' },
          { value: 15, name: '厦门' }
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  };
  barchart.setOption(batoption);
  // 折线图
  const linecahrt = echarts.init(lineContainer.value);
  const lineoption = {
    title: {
      text: '近7天开单总量统计',
    },
    responsive: true,
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    grid: {
      left: '3%',
      right: '5%',
      bottom: '3%',
      containLabel: true
    },
    legend: {
      data: ['未付款', '付定金', '成交']
    },
    toolbox: {
      show: true,
      feature: {
        saveAsImage: { show: true }
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['2024-11-20', '2024-11-21', '2024-11-22', '2024-11-23', '2024-11-24', '2024-11-25', '2024-11-26']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name: '成交',
        color: '#f1c40f',
        type: 'line',
        areaStyle: {},
        emphasis: {
          focus: 'series'
        },
        label: {
          show: true,
          position: 'top'
        },
        data: [10, 12, 21, 20, 26, 18, 15],
      },
      {
        name: '付定金',
        color: '#2b88d8',
        type: 'line',
        areaStyle: {},
        emphasis: {
          focus: 'series'
        },
        data: [11, 15, 10, 8, 9, 12, 10]
      },
      {
        name: '未付款',
        color: '#ff3838',
        type: 'line',
        areaStyle: {},
        emphasis: {
          focus: 'series'
        },
        data: [2, 5, 7, 3, 1, 2, 0]
      }
    ]
  }
  linecahrt.setOption(lineoption);
});
const source = ref(0)
const outputValue = useTransition(source, {
  duration: 1500,
})
source.value = 172000
</script>
<template>
  <div class="box_main">
    <div class="bx main">
      <el-row>
        <el-col :span="4">
          <div class="statistic-card">
            <el-statistic :value="10">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  今日<span class="green">成交</span>单数
                  <el-tooltip effect="dark" content="数据来源于实时统计" placement="top">
                    <el-icon style="margin-left: 4px" :size="12">
                      <Warning />
                    </el-icon>
                  </el-tooltip>
                </div>
              </template>
            </el-statistic>
          </div>
        </el-col>
        <el-col :span="4">
          <div class="statistic-card">
            <el-statistic :value="12">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  今日<span class="yellow">付定金</span>单数
                  <el-tooltip effect="dark" content="数据来源于实时统计" placement="top">
                    <el-icon style="margin-left: 4px" :size="12">
                      <Warning />
                    </el-icon>
                  </el-tooltip>
                </div>
              </template>
            </el-statistic>
          </div>
        </el-col>
        <el-col :span="4">
          <div class="statistic-card">
            <el-statistic :value="8">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  今日<span class="red">未付款</span>单数
                  <el-tooltip effect="dark" content="数据来源于实时统计" placement="top">
                    <el-icon style="margin-left: 4px" :size="12">
                      <Warning />
                    </el-icon>
                  </el-tooltip>
                </div>
              </template>
            </el-statistic>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="statistic-card">
            <el-statistic :value="outputValue">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  今日成交量
                  <el-tooltip effect="dark" content="提示" placement="top">
                    <el-icon style="margin-left: 4px" :size="12">
                      <Warning />
                    </el-icon>
                  </el-tooltip>
                </div>
              </template>
            </el-statistic>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="statistic-card">
            <el-statistic :value="72000" title="New transactions today">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  New transactions today
                </div>
              </template>
            </el-statistic>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="footer">
      <!-- 折线图 -->
      <div ref="lineContainer" class="bx chart"></div>
      <!-- 饼图 -->
      <div ref="barContainer" class="bx chart"></div>
    </div>
    <div class="list">
      <el-card shadow="hover">
        <template #header>南斯拉夫白</template>
        <img src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"
             style="width: 100%" />
      </el-card>
    </div>
  </div>
</template>

<style scoped>
div.bx {
  box-shadow: var(--el-box-shadow);
  border-radius: 4px;
  margin-bottom: 15px;
}

.header {
  display: flex;
  padding: 10px 10px 0;
  overflow: hidden;
}

.main {
  display: flex;
  width: 100%;
  overflow: hidden;
}

.footer {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.footer .chart {
  width: 49%;
  height: 400px;
  padding: 5px;
  overflow: hidden;
}

.main .el-row {
  flex: 1;
}

.main .el-col {
  padding: 20px;
  text-align: center;
}

.list {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.list .el-card {
  min-width: 300px;
}
.list .el-card:hover{
  cursor: pointer;
}
.statistic-card{
  padding: 16px;
  background: #f5f5f9;
}
.el-main {
  overflow: hidden;
}

.el-statistic {
  --el-statistic-content-font-size: 28px;
}

.statistic-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--el-text-color-regular);
  margin-top: 16px;
}

.statistic-footer .footer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.statistic-footer .footer-item span:last-child {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.green {
  color: var(--el-color-success);
}

.red {
  color: var(--el-color-error);
}

.yellow {
  color: var(--el-color-warning);
}
</style>